package com.sure0000.basic;

import com.alibaba.fastjson.JSONObject;

import java.math.BigDecimal;

/**
 * @desc
 * @Author xuyouchang
 * @Date 2021/10/27
 */
public class JsonTest {
    public static void main(String[] args) {
        String jsonStr = "{\n" +
                "  \"eid\": \"504715240\",\n" +
                "  \"vehicle_color\": \"\",\n" +
                "  \"plate_color\": \"4\",\n" +
                "  \"pass_time\": 1635308324000,\n" +
                "  \"plate_color_is_blue\": \"true\",\n" +
                "  \"receive_time\": 1635308473493,\n" +
                "  \"insert_time\": 1635308473493,\n" +
                "  \"serial_number\": \"784286126\",\n" +
                "  \"record_id\": \"d5490b7c0e1f4f9dac62f72b5f4ea16d\",\n" +
                "  \"plate_code_snap\": \"渝AFJ701\",\n" +
                "  \"upload_time\": 1635308372000,\n" +
                "  \"reader_ip\": \"null\",\n" +
                "  \"administrative_region\": \"\",\n" +
                "  \"plate_code_rfid\": \"渝AFJ701\",\n" +
                "  \"pic_url\": \"http://10.0.0.117:8081/149043,043926d99a803ef2d8?ttl\\u003d2M\",\n" +
                "  \"collection_point_direction_code\": \"50011250009303\"\n" +
                "}";

        JSONObject jsonObject = JSONObject.parseObject(jsonStr);
        jsonObject.forEach((k, v) -> {
            //以下几种情况kafka包装schema会出错，需要转换类型
            if (v instanceof BigDecimal
                    ) {
                v = ((BigDecimal) v).floatValue();
            }

            if(v instanceof Integer
                    ){
                v = ((Integer)v).longValue();
            }

        });
    }
}
